package com.aaa.rent.service.impl;
import com.aaa.entity.Car;
import com.aaa.rent.dao.CarDao;
import com.aaa.rent.service.CarService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author wys
 * @version 1.0
 * @date 2023/3/1 11:24
 */
@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarDao CarDao;


    @Override
    public Result insert(Car car) {
        int insert = CarDao.insert(car);
        return new Result(2000,"增加成功",insert);
    }

    @Override
    public Result update(Car car) {
        int update = CarDao.updateById(car);
        return new Result(2000,"编辑成功",update);
    }

    @Override
    public Result selectAllCars(Integer currentPage, Integer pageSize, String carName) {
        PageHelper.startPage(currentPage,pageSize);
        List<Car> cars = CarDao.selectAllCars(carName);
        PageInfo<Car> pageInfo = new PageInfo<>(cars);
        return new Result(2000,"成功",pageInfo);
    }

    @Override
    public Result delete(Integer id) {
        return new Result(2000,"成功",CarDao.deleteById(id));
    }

    @Override
    public Integer updateState(Integer id) {
        return CarDao.updateState(id);
    }


}
